package report

import "shqsoft.cn/pasnj/base"
import "time"

//ParentCatalog 父级目录
type ParentCatalog struct {
	ID   int    `gorm:"AUTO_INCREMENT;primary_key;column:MLID"`
	Name string `gorm:"column:MLMC;size:30"`
}

//TableName ParentCatalog表名称
func (ParentCatalog) TableName() string {
	return "BI_CATALOG"
}

//Catalog 报表目录
type Catalog struct {
	ID          int           `gorm:"primary_key;column:MLID"`
	Name        string        `gorm:"column:MLMC;size:30"`
	ParentID    int           `gorm:"column:SSML"`
	Description string        `gorm:"column:MLSM;size:300"`
	Parent      ParentCatalog `gorm:"ForeignKey:ParentID"`
}

//TableName Catalog表名称
func (Catalog) TableName() string {
	return "BI_CATALOG"
}

//Report 报表目录
type Report struct {
	ID          int        `gorm:"primary_key;column:BBID"`
	Name        string     `gorm:"column:BBMC;size:30"`
	UserID      int        `gorm:"column:FBR;"`
	CreateTime  time.Time  `gorm:"column:CJSJ;type:date;"`
	CatalogID   *int       `gorm:"column:SSML"`
	Description string     `gorm:"column:BBSM;size:300"`
	Catalog     *Catalog   `gorm:"ForeignKey:CatalogID"`
	IsPublish   bool       `gorm:"column:ISFB"`
	PublishTime *time.Time `gorm:"column:FBSJ;type:date;"`
	Config      string     `gorm:"column:BBPZ;"`
	Authorities string     `gorm:"column:BBQX;"`
	Type        string     `gorm:"column:BBLX;size:1"`
}

//TableName Report表名称
func (Report) TableName() string {
	return "BI_REPORT"
}

//CatalogEF 返回Catalog类对象
func CatalogEF() base.EntityFunc {
	return func() interface{} {
		entity := Catalog{}
		return &entity
	}
}

//CatalogESF 返回Catalog类对象列表
func CatalogESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []Catalog
		return &entities
	}
}

//ParentCatalogEF 返回ParentCatalog类对象
func ParentCatalogEF() base.EntityFunc {
	return func() interface{} {
		entity := ParentCatalog{}
		return &entity
	}
}

//ParentCatalogESF 返回ParentCatalog类对象列表
func ParentCatalogESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ParentCatalog
		return &entities
	}
}

//ReportEF 返回Report类对象
func ReportEF() base.EntityFunc {
	return func() interface{} {
		entity := Report{}
		return &entity
	}
}

//ReportESF 返回Report类对象列表
func ReportESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []Report
		return &entities
	}
}

func init() {
	relationship1 := []string{"Parent"}
	base.DaoPoolObj.Put("Catalog", base.NewDefaultDao(CatalogEF(), CatalogESF(), relationship1))
	base.DaoPoolObj.Put("ParentCatalog", base.NewDefaultDao(ParentCatalogEF(), ParentCatalogESF(), nil))
	relationship2 := []string{"Catalog"}
	base.DaoPoolObj.Put("Report", base.NewDefaultDao(ReportEF(), ReportESF(), relationship2))
}
